package com.yx.cloud.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.yx.cloud.R;
import com.yx.cloud.utils.RomUtils;
import java.util.List;

public class RoomRenameAdapter extends RecyclerView.Adapter implements View.OnClickListener {
    private static final String TAG = "RoomRenameAdapter";
    private Context context;
    private List<String> list;
    private RoomRenameAdapter.InnerItemOnclickListener listener;

    public RoomRenameAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View viewLocalMap = LayoutInflater.from(context).inflate(R.layout.room_rename_item,parent,false);
        RoomRenameAdapter.MyViewHolder viewHolder = new RoomRenameAdapter.MyViewHolder(viewLocalMap);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        String name = list.get(position);
        RoomRenameAdapter.MyViewHolder myViewHolder = (RoomRenameAdapter.MyViewHolder) holder;
        myViewHolder.tvRoomName.setText(getSpecifiedName(name));
        myViewHolder.rlRoomName.setOnClickListener(this);
        myViewHolder.rlRoomName.setTag(position);
    }

    public String getSpecifiedName(String name){
         /*
        "yxroom_name_1" = "客厅";
        "yxroom_name_2" = "主卧";
        "yxroom_name_3" = "次卧";
        "yxroom_name_4" = "衣帽间";
        "yxroom_name_5" = "玄关";
        "yxroom_name_6" = "阳台";
        "yxroom_name_7" = "厨房";
        "yxroom_name_8" = "书房";
        "yxroom_name_9" = "餐厅";
        "yxroom_name_10" = "儿童房";
        "yxroom_name_11" = "卫生间";
        */
        String specifiedName = name;
        if ("yxroom_name_1".equals(name)) {
            specifiedName = context.getString(R.string.MM_MasterBedroom);
        } else if ("yxroom_name_2".equals(name)) {
            specifiedName = context.getString(R.string.MM_LivingRoom);
        } else if ("yxroom_name_3".equals(name)) {
            specifiedName = context.getString(R.string.MM_SecondBedroom);
        } else if ("yxroom_name_4".equals(name)) {
            specifiedName = context.getString(R.string.MM_Cloakroom);
        } else if ("yxroom_name_5".equals(name)) {
            specifiedName = context.getString(R.string.MM_Vestibule);
        } else if ("yxroom_name_6".equals(name)) {
            specifiedName = context.getString(R.string.MM_Balcony);
        } else if ("yxroom_name_7".equals(name)) {
            specifiedName = context.getString(R.string.MM_Kitchen);
        } else if ("yxroom_name_8".equals(name)) {
            specifiedName = context.getString(R.string.MM_StudyRoom);
        } else if ("yxroom_name_9".equals(name)) {
            specifiedName = context.getString(R.string.MM_DiningRoom);
        } else if ("yxroom_name_10".equals(name)) {
            specifiedName = context.getString(R.string.MM_KidBedroom);
        } else if ("yxroom_name_11".equals(name)) {
            specifiedName = context.getString(R.string.MM_Bathroom);
        }
        return specifiedName;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    @Override
    public void onClick(View v) {
        if (RomUtils.isFastClick()) {
            return;
        }
        listener.itemClick(v,(int)v.getTag());
    }

    public interface InnerItemOnclickListener {
        void itemClick(View v,int position);
    }

    public void setOnInnerItemOnClickListener(RoomRenameAdapter.InnerItemOnclickListener listener) {
        this.listener = listener;
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        RelativeLayout rlRoomName;
        TextView tvRoomName;
        public MyViewHolder(View itemView) {
            super(itemView);
            rlRoomName = itemView.findViewById(R.id.ll_room_rename);
            tvRoomName = itemView.findViewById(R.id.tv_room_rename_text);
        }
    }
}
